package com.tian.controller.station.api;

import com.tian.common.annotation.LoginCheckAnnotation;
import com.tian.common.util.CommonResult;
import com.tian.dto.market.BaseReqPageDto;
import com.tian.dto.market.BaseRespPageDto;
import com.tian.dto.station.*;
import com.tian.service.station.ChargeStationService;
import org.redisson.api.RedissonClient;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * {@code @description:} 站点信息
 *
 * @author tianwc 公众号：Java后端技术全栈
 * 在线刷题 1200+java面试题和1000+篇技术文章：<a href="https://woaijava.cc/">博客地址</a>
 * {@code @date:} 2024/1/18 18:51
 * {@code @version:} 1.0
 */
@RestController
@RequestMapping("/station/api/station")
public class ChargeStationApiController {

    @Resource
    private ChargeStationService chargeStationService;
    @Resource
    private RedissonClient redissonClient;


    @PostMapping("/page")
    public CommonResult<StationQueryPageRespDto> listByPage(@RequestBody ChargeStationQueryPageReqDto chargeStationQueryPageReqDto) {
        return chargeStationService.listByPageApi(chargeStationQueryPageReqDto);
    }

    /**
     * 站点详情
     *
     * @param id 充电站id
     * @return 充电站信息
     */
    @GetMapping("/{id}")
    public CommonResult<StationRespDto> getStationById(@PathVariable("id") Integer id) {
        return chargeStationService.findById(id);
    }
    /**
     * 站点详情
     *
     * @param id 充电站id
     * @return 充电站信息
     */
    @GetMapping("/gun/{id}")
    public CommonResult<GunRespDto> getStationGunById(@PathVariable("id") Integer id) {
        return chargeStationService.findByGunId(id);
    }
    /**
     * 站点充电桩数据统计
     *
     * @param id 充电站id
     * @return 充电站充电桩数据统计
     */
    @GetMapping("/count/{id}")
    public CommonResult<ChargeStationGunCountRespDto> countById(@PathVariable("id") Integer id) {
        return null;
    }

    /**
     * 随机获取一个可用的充电站充电桩
     */
    @GetMapping("/random/available")
    public CommonResult<GunRespDto> getRandomAvailable() {
        return chargeStationService.getRandomAvailable();
    }

    @PostMapping("/my/list")
    @LoginCheckAnnotation
    public CommonResult<BaseRespPageDto<List<MyStationRespDto>>> myStationList(@RequestBody BaseReqPageDto baseReqPageDto) {
        return chargeStationService.myStationList(baseReqPageDto);
    }

    @GetMapping("/test")
    public void test() {
        int stationId = 18;
        int id = 9;
//        String unavailableKey = "station_"+stationId+":unavailable";
        String availableKey = "station_"+stationId+":available";
        redissonClient.getSet(availableKey).remove(id);
    }
}
